<extend name="Base/base" />
<block name="body">
<div class="row with-padding bg-primary" style="font-size:20px; padding:10px 0px;">
  <div class="col-xs-3 text-center">
    <a href="/index/product" style="color:#ffffff;"><i class="icon-chevron-left"></i></a> 
  </div>
  <div class="col-xs-6 text-center">
    <strong>报告查询</strong>
  </div>
  <div class="col-xs-3 text-center">
    <a href="/user/home" style="color:#ffffff;"><i class="icon-user"></i></a> 
  </div>
</div>
<div class="container" style="margin-top:20px;">
  <blockquote>报告查询</blockquote>  
  <form class="form-horizontal" method="post">
    <input type="hidden" id="search_id" value="0"/>
    <input type="hidden" id="trade_no" value="{$trade_no}"/>
    <div class="form-group">
      <div class="col-xs-12">
        <input type="text" class="form-control input-lg" id="name" name="name" placeholder="请输入真实姓名">
      </div>
    </div>
    <div class="form-group">
      <div class="col-xs-12">
        <input type="text" class="form-control input-lg" id="id_card" name="id_card" placeholder="请输入身份证号">
      </div>
    </div>
    <div class="form-group">
      <div class="col-xs-12">
      <input type="text" class="form-control input-lg" id="phone" name="phone" placeholder="请输入手机号">
      </div>
    </div>
    <div class="form-group">
      <div class="col-xs-8">
        <input type="text" class="form-control input-lg" id="code" name="code" placeholder="输入短信验证码">
      </div>
      <div class="col-xs-4">
        <a href="javascript:;" onclick="send_vcode();" id="vcode_btn" class="btn btn-block btn-primary btn-lg" style="font-size:14px; padding:12px 16px;">获取验证码</a>
      </div>
    </div>
    <div class="form-group">
      <div class="col-xs-12">
        <input type="text" class="form-control input-lg" id="pass" name="pass" placeholder="请设置查看历史报告密码">
      </div>
    </div>
    <div class="form-group">
      <div class="col-xs-12">
        <div class="checkbox">
          <label>
            <input type="checkbox" checked disabled> 同意<a href="/info/info_1">《隐私政策》</a> 和 <a href="/info/info_2">《全网咨信服务协议》</a> 
          </label>
        </div>
      </div>
    </div>
    <button class="btn btn-warning btn-block btn-lg" id="pay_btn" type="button">打赏查询</button>
  </form>
</div>
</block>
<block name="js">
<script>
$('#pay_btn').on('click', function(){
  var name = $('#name').val();
  var id_card = $('#id_card').val();
  var phone = $('#phone').val();  
  var pass = $('#pass').val();
  var code = $('#code').val();
  var trade_no = $('#trade_no').val();

  if (name == '') {
    alert('请输入姓名');
    return false;
  }
  if (id_card == '') {
    alert('请输入身份证号');
    return false;
  }
  if (phone == '') {
    alert('请输入手机');
    return false;
  }
  if (pass == '') {
    alert('请输入查询密码');
    return false;
  }
  if (code == '') {
    alert('请输入验证码');
    return false;
  }

  $.ajax({
    url: '/search/search_log',
    type: 'post',
    dataType: 'json',
    data: {'name': name, 'id_card':id_card, 'phone': phone, 'pass': pass, 'code': code, 'trade_no':trade_no},
    success: function(res) {
      if (res.status != 1) {
        alert(res.msg);
        return false;
      } else {
        var search_id = res.id;
        $('#search_id').val(search_id);
        callpay();
      }
    }
  });
});


var countdown=60; 
function send_vcode(){
  var obj = $("#vcode_btn");
  var mobile = $('#phone').val();
  if ( ! obj.attr('disabled')) {
    $.ajax({
      url: '/public/send_vcode',
      type: 'POST',
      dataType: 'json',
      data: {'mobile': mobile, 'type':2},
      success:function(res) {
        if (res.status != 1) {
          alert(res.message);
        }
      }
    });
  }
  settime(obj);
}

function settime(obj) { //发送验证码倒计时
  if (countdown == 0) { 
    obj.attr('disabled',false); 
    obj.html("获取验证码");
    countdown = 60; 
    return;
  } else { 
    obj.attr('disabled',true);
    obj.html("重新发送(" + countdown + ")");
    countdown--; 
  } 
  setTimeout(function() { 
    settime(obj) }
    ,1000) 
}

function jsApiCall()
{
  WeixinJSBridge.invoke(
      'getBrandWCPayRequest',
      {$jsApiParameters},
      function(res){
        WeixinJSBridge.log(res.err_msg);
        if (res.err_msg=='get_brand_wcpay_request:ok') {
          //支付
          var search_id = $('#search_id').val();
          window.location.href = "/search/get_report/id/" + search_id;
        } else {
          //alert(0);
        }                                                          
      }
    );
}

function callpay()
{
  if (typeof WeixinJSBridge == "undefined"){
    if( document.addEventListener ){
      document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
    }else if (document.attachEvent){
      document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
      document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
    }
  }else{
    jsApiCall();
  }
}
</script>
</block>
